package com.ssii.www.myproject.web.controller;

import com.ssii.www.myproject.common.util.UserContext;
import com.ssii.www.myproject.domain.Menu;
import com.ssii.www.myproject.domain.User;
import com.ssii.www.myproject.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/menu")
public class MenuController  {

  @Autowired
  private MenuService menuService;
  @RequestMapping("/index")
  public String index(){
    return "menu/index";
  }

  @RequestMapping("/loadTree")
  @ResponseBody
  public List<Menu> loadTree(){
    User user = UserContext.getUser();
    List<Menu> menus = menuService.loadTreeByUserId(user.getId());
    return menus;
  }
}
